const env = getEnv()
const configs = {
  loacl: {
    server: 'http://127.0.0.1:7001',
    // server: 'https://t.babo.linkzl.com',
  },
  develop: {
    server: 'https://t.babo.linkzl.com',
    // server: 'http://127.0.0.1:7001',
  },
  trial: {
    server: 'https://t.babo.linkzl.com',
  },
  release: {
    server: 'https://babo.linkzl.com',
  },
}

const config = configs[env] || configs.release

function getEnv() {
  let env = uni.getStorageSync('env')

  if (!env) {
    // #ifdef H5
    if (['127.0.0.1', 'localhost', '192.168'].some((val) => location.hostname.includes(val))) env = 'loacl'
    // #endif

    // #ifdef MP-WEIXIN
    const accountInfo = wx.getAccountInfoSync()
    env = accountInfo.miniProgram.envVersion
    // #endif
  }

  console.log('env', env)

  return env || 'release'
}

export default {
  env,
  apiUrl: uni.getStorageSync('apiUrl') || config.server + '/api', // API地址

  root: '/h5',
  userKey: 'user', // 本地存储的登录用户key
  tokenKey: 'token', // 本地存储的token key

  // 登录页面
  // #ifdef H5
  // loginPage: '/pages/mobile-login/mobile-login', // 手机号登录
  // loginPage: '/pages/login/login',
  loginPage: '/pages/auth-login/auth-login',
  // #endif
  // #ifdef MP-WEIXIN
  loginPage: '/pages/auth-login/auth-login',
  // #endif

  version: '1.0.0',
  ...config,
}
